#include <iostream>
#include <string.h>
#include <fstream>
#include "SortingConfig.h"

using namespace std;

void swap(int &a, int &b) {
    int t=a;
    a = b;
    b = t;
}

void count_sort(int *arr, int n) {
    // 计数排序算法
    // 计算数组中的最大值和最小值
    int minNum=INT32_MAX, maxNum=INT32_MIN;
    for(int i=0; i<n; ++i) {
        if (arr[i] < minNum) minNum = arr[i];
        if (arr[i] > maxNum) maxNum = arr[i];
    }
    // 初始化计数数组
    int count[maxNum - minNum + 1];
    memset(count, 0, sizeof(count));
    // 计数
    for (int i=0; i<n; ++i) {
        count[arr[i]-minNum] ++;
    }
    // 根据计数输出排序后的结果
    for(int j=0,i=0; j<=maxNum-minNum; ++j) {
        for(int k=0; k<count[j]; ++k,++i) arr[i] = j+minNum;
    }
}

int main(int argc, char *argv[]) {
    cout << "Sorting Version: " << Sorting_VERSION_MAJOR 
         << "." << Sorting_VERSION_MINOR<<endl;
    // 参数解析
    ifstream input;
    if (argc > 1) {
        input.open(argv[1], ios::in);
    }

    int n;
    if (argc > 1) input >> n;
    else cin >> n;
    int arr[n];
    if (argc > 1){
        for(int i=0; i<n;++i) input >> arr[i];
        input.close();
    } else {
        for(int i=0; i<n;++i) cin >> arr[i];
    }
    // 排序
    count_sort(arr, n);

    for(int i=0; i<n; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;

    return 0;
}